package com.xjx.controller;

import com.xjx.enmus.DrinkType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/drink")
public class DrinkController {

    @GetMapping("/{type}")
    public ResponseEntity<String> getDrinkDescription(@PathVariable String type) {
        try {
            // 将路径变量转换为大写，以便匹配枚举常量
            DrinkType drinkType = DrinkType.valueOf(type.toUpperCase());
            String responseMessage = String.format("您选择的是：%s", drinkType.getDescription());
            return ResponseEntity.ok(responseMessage);
        } catch (IllegalArgumentException e) {
            // 如果传入的值无法匹配任何枚举，则抛出此异常
            return ResponseEntity.badRequest().body("无效的饮品类型: " + type);
        }
    }
}
